package com.mybatis.plus.join.column;

import com.mybatis.plus.join.ColumnData;
import lombok.Data;

@Data
public class DivideColumn implements Column {
    private Column column0;
    private Column column1;
    private String asName;


    public DivideColumn(Column column0, Column column1) {
        this.column0 = column0;
        this.column1 = column1;
    }

    public DivideColumn(Column column0, Column column1, String asName) {
        this.column0 = column0;
        this.column1 = column1;
        this.asName = asName;
    }

    @Override
    public String selectColumn() {
        if (asName == null || "".equals(asName.trim())) {
            return column0.selectColumn() + " / " + column1.selectColumn();
        }
        return "(" + column0.selectColumn() + " / " + column1.selectColumn() + ") AS " + asName;
    }

    @Override
    public void fillData(ColumnData columnData) {
        column0.fillData(columnData);
        column1.fillData(columnData);
    }
}